<?php
namespace app\lib\baidu;
use think\Db;

class Api360 
{

    public function chat($api_url,$messages,$api_param){
        $params = [
            'message'=>$messages,
            'session_id'=>$api_param['session_id'],
            'stream'=>false,
            'model_id'=>$api_param['model_id']
        ];
        $result = httpRequest($api_url,json_encode($params,JSON_UNESCAPED_UNICODE),'POST',[
                'Content-Type: application/json',
                'yy_user_id:'.$api_param['yy_user_id'],
                'yy_user_name:'.$api_param['yy_user_name']
            ]);
        // Db::name('test')->insert(['content'=>'-----'.$result]);
        // Db::name('test')->insert(['content'=>'-----'.json_encode($params,JSON_UNESCAPED_UNICODE)]);
        // dump($result);die;
        $result = json_decode($result,true);
        if ( $result['code'] == '1000' ) {
            return ['status'=>1,'answer'=>$result['data']['answer']];
        }else{
            return ['status'=>0,'msg'=>$result['msg']];
        }
    }

}
